﻿#include"SList.h"

int test1()
{
	//创建节点
	SLTNode* node1 = (SLTNode*)malloc(sizeof(SLTNode));//申请一个节点大小的空间
	SLTNode* node2 = (SLTNode*)malloc(sizeof(SLTNode));
	SLTNode* node3 = (SLTNode*)malloc(sizeof(SLTNode));
	SLTNode* node4 = (SLTNode*)malloc(sizeof(SLTNode));

	node1->data = 1;
	node2->data = 2;
	node3->data = 3;
	node4->data = 4;

	node1->next = node2;
	node2->next = node3;
	node3->next = node4;
	node4->next = NULL;
	//打印
	SLTNode* plist = node1;//头结点
	SLTPrint(plist);
}

void test2()
{
	//头结点
	SLTNode* plist =NULL;
	//尾插
	SLTPushBack(&plist, 1);
	SLTPushBack(&plist, 2);
	SLTPushBack(&plist, 3);
	SLTPushBack(&plist, 4);
	SLTPrint(plist);
	//头插
	SLTPushFront(&plist, 5);
	SLTPrint(plist);
	//尾删
	SLTPopBack(&plist);
	SLTPrint(plist);
	//头删
	SLTPopFront(&plist);
	SLTPrint(plist);
	//查找
	SLTNode* pos=SLTFind(plist, 2);
	////在指定位置之前插入
	//SLTInsert(&plist, pos, 100);
	//SLTPrint(plist);
	////在指定位置之后插⼊数据
	//SLTInsertAfter(pos, 100);
	//SLTPrint(plist);
	////在指定位置删除
	//SLTErase(&plist, pos);
	//SLTPrint(plist);
	//删除指定位置之后的
	SLTEraseAfter(pos);
	SLTPrint(plist);
	//销毁
	SListDestroy(&plist);
}
int main()
{
	//test1();
	test2();
	return 0;
}